<?php

class Silk_Templates extends Silk_Gateway {

    protected $_dao_class = 'Silk_Dao_Template';

    protected $_model_class = 'Silk_Template';

    protected $_primary_key = 'template_id';


    public function getType($pTemplate){

	$template = $this->getModelObject($pTemplate);

	$Types = new Silk_Types();
	return $Types->fetch($template->type_id);
    }

    public function getTemplatesForType($pTypeId){
	return $this->fetch(array('type_id' => $pTypeId));
    }

    public function getTemplateForTypeByName($pTypeId, $pAction){

// 	logdebug("Silk_Templates.getTemplateForTypeByName: Getting $pAction for type $pTypeId");
	$results = $this->fetch(array('type_id' => $pTypeId, 'name' => $pAction));
	if (count($results) > 0)
	    return $results->current();
	else
	    return null;
    }

//     public function getModelCollection($pTemplates){
// 	if ($pTemplates instanceof FP_Model_Collection){
// 	    return $pTemplates;
// 	} else if (is_array($pTemplates)) {
// 	    $templates = array();
//
// 	    foreach ($pTemplates as $template){
// 		if ($template instanceof Silk_Template || is_array($template))
// 		    $templates[] = $template;
// 	    }
//
// 	    return parent::getModelCollection($templates);
// 	} else
// 	    return parent::getModelCollection($pTemplates);
//     }
}

?>